// 校验token中间件
import { DefaultContext, Next } from "koa";
// import { respondResult } from "../utils/public";
// import { Code, NotifyMsg } from "../config/errorCode";
// import Tools from "../utils/tools";

export default async (ctx: DefaultContext, next: Next) => {
    // ignore favicon
    if (ctx.path === "/favicon.ico") return;

    if (ctx.session.isNew) {

        ctx.session.sessionId = ctx.hostname + "_" + Date.now();
        ctx.session.save();
        console.log("user has not logged in");
        // ctx.body = respondResult(Code.hasNotLogin, NotifyMsg.hasNotLogin);
    } else {
        console.log(ctx.session.sessionId);
        console.log("user has already logged in");
    }

    await next();
};
